package cn.lx.log.autoconfigure;

import cn.lx.log.core.annotation.DynamicLogAdvice;
import cn.lx.log.core.annotation.EnableLog;
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 日志组件自动配置类
 * @author lX
 * @version JDK 8
 * @className LogAutoConfiguration (此处以class为例)
 * @date 2024/5/22
 * @description TODO
 */
@Configuration
@ConditionalOnClass(EnableLog.class)
@EnableConfigurationProperties({LogProperties.class})
public class LogAutoConfiguration {




    @Bean
    public DynamicLogAdvice dynamicLogAdvice(LogProperties logProperties){
        return new DynamicLogAdvice(logProperties);
    }


    @Bean("logPointcutAdvisor")
    public AspectJExpressionPointcutAdvisor autoLogPointcutAdvisor(LogProperties logProperties) {
        AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
        advisor.setExpression(logProperties.getPointcut());
        advisor.setAdvice(dynamicLogAdvice(logProperties));
        return advisor;
    }
}
